<template>
	<view class="pageAll">
		<view v-if="info">
			<view>
				<signatureFileInfo :info="info"/>
			</view>
			<view class="bottomBtnView" v-if="info.status === 'be_confirmed'">
				<button class="bottomBtn lightRed" @click="refuseOrder" hover-class="subActive">
					拒绝选品单
				</button>
				<button class="bottomBtn redBtn" @click="submitOrder" hover-class="subActive">
					确认选品单
				</button>
			</view>
		</view>
		<nonePage v-else />
		<comFilePass @cancelPass="cancelPass" @submitPass="submitPass" :fliePassVisible="fliePassVisible" />
		<myToast :toastVisible="myToastVisible" :tipMess="toastTip" />
		<popupRefuse :modelVisible="refusePopVis" :type="1" @submitRufuse="submitRufuse" @cancelRufuse="cancelRufuse" />
	</view>
</template>

<script>
	import myToast from '../../../components/message/myToast.vue'
	import comFilePass from '../../../components/purchaseOrder/confirmFliePass.vue'
	import signatureFileInfo from "../../../components/foodReport/signatureFileInfo.vue"
	import popupRefuse from '../../../components/purchaseOrder/popupRefuse.vue'
	import {
		HBValidate
	} from '../../../utils/tools.js'
	import nonePage from '../../../components/commonCom/nonePage.vue'
	export default {
		data() {
			return {
				fliePassVisible: false,
				myToastVisible: false,
				toastTip: '',
				refusePopVis: false,
				info: {},
				reportId: null,
			}
		},
		methods: {
			// 取消拒绝提报
			cancelRufuse() {
				this.refusePopVis = false
			},
			// 拒绝提报
			submitRufuse(value) {
				if (value.result) {
					this.$api.submissionRefuse({
							id: this.reportId,
							refuse: value.result
						})
						.then(res => {
							if (res.status) {
								this.refusePopVis = false
								uni.showToast({
									title: '拒绝选品单成功',
									duration: 1000,
									icon: 'success'
								})

								this.$store.commit('setCurrTag', 4)
								this.$store.commit('setSubCurrTag', 2)

								setTimeout(() => {
									uni.switchTab({
										url: '../foodReport/foodReport'
									})
								}, 1000)
							} else {
								this.refusePopVis = false
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 1500,
								})
							}
						})
				} else {
					uni.showToast({
						title: '内容不能为空',
						icon: 'none',
						duration: 1500
					})
				}
			},
			// 弹窗填写拒绝信息的弹窗
			refuseOrder() {
				this.refusePopVis = true
			},
			// 弹窗确认提报的弹窗
			submitOrder() {
				this.fliePassVisible = true
			},
			// 确认提报
			submitPass(value) {
				const validate = new HBValidate()
				if (validate.isFilePwd(value)) {
					this.$api.submissionAffirm({
							id: this.reportId,
							order_password: value
						})
						.then(res => {
							if (res.status) {
								this.fliePassVisible = false
								this.toastTip = '选品单确认成功'
								this.myToastVisible = true
								if(this.toastTip == '选品单确认成功'){
									this.$api.addGoods({
										token:this.$store.state.token,
										id: this.reportId,
									}).then(res => {
										console.log(res)
									}).catch(err => {
										console.log(err)
									})
								}
								this.$store.commit('setCurrTag', 4)
								this.$store.commit('setSubCurrTag', 2)

								setTimeout(() => {
									uni.switchTab({
										url: '../foodReport/foodReport'
									})
									this.myToastVisible = false
								}, 2000)
							} else {
								this.fliePassVisible = false
								uni.showToast({
									title: res.msg,
									duration: 2000,
									icon: 'none'
								})
							}
						})
				} else {
					uni.showToast({
						title: '文件确认密码格式错误',
						icon: 'none',
						duration: 1500
					})
				}
			},
			// 取消确认提报
			cancelPass() {
				this.fliePassVisible = false
			},
			// 获取用户信息
			getInfo(id) {
				this.$api.submissionMessage({
						id: id
					})
					.then(res => {
						if (res.status) {
							this.info = res.data
						} else {
							this.info = null
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 1500,
							})
						}
					})
					.catch(err => {
						this.info = null
						uni.showToast({
							title: '加载失败',
							icon: 'none',
							duration: 1500,
						})
						setTimeout(() => {
							uni.switchTab({
								url: '../foodReport/foodReport'
							})
						}, 1500)
					})
			}
		},
		components: {
			signatureFileInfo,
			comFilePass,
			myToast,
			popupRefuse,
			nonePage,
		},
		onLoad(option) {
			this.reportId = parseInt(option.id)
			this.getInfo(parseInt(option.id))
		},
		onShareAppMessage: (options) => {
			// 设置菜单中的转发按钮触发转发事件时的转发内容
			var shareObj = {
				title: "红标HONBIAO", // 默认是小程序的名称(可以写slogan等)
				path: '/pages/indexPage/authorization/authorization', // 默认是当前页面，必须是以‘/’开头的完整路径
				imageUrl: '/static/index/labelRouge.png', //自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
				success: (res) => {
					// 转发成功之后的回调
					if (res.errMsg == 'shareAppMessage:ok') {}
				},
				fail: () => {
					// 转发失败之后的回调
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						// 用户取消转发
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				}
			};
			return shareObj
		},
	}
</script>

<style scoped>
	.pageAll {
		box-sizing: border-box;
		background-color: #fdf5f3;
		width: 100%;
		height: 100%;
		padding: 0 17upx;
		display: inline-block;
		position: fixed;
		overflow-y: auto;
	}

	.bottomBtnView {
		display: flex;
		justify-content: space-between;
		margin-bottom: 20upx;
	}

	.bottomBtn {
		font-size: 36upx;
		letter-spacing: 10upx;
		text-indent: 10upx;
		width: 48%;
	}

	.bottomBtn:after {
		border: none;
	}

	.redBtn {
		background-color: #f7533e;
		color: #FFF;
	}

	.lightRed {
		background-color: #ffc8c7;
		color: #666666;
	}

	.subActive {
		background-color: #F3D6D4;
	}
</style>
